# ======================================================================
#
# Copyright (C) ADN
# Icon.pl
# Description:
#  - Cree l icone dans le Systray et clean les processus
#  - Put the icon in the Systray and clean the process
#
# ======================================================================

use strict;
use SysTray;
#use threads;
use Time::HiRes qw(sleep);
use ADN::CONF::Read;
use ADN::CONF::Path;
use ADN::SERVER::StartUP;

# #######################
# CREATE THE TRAY ICON
# #######################
my ( $exe , $ico ) = ADN::SERVER::StartUP->folder();
$ico .= 'icon.ico';
SysTray::create('my_callback', $ico, 'Console');
while (1) {
    SysTray::do_events();
    sleep 0.1;
}

# #######################
# DOUBLE & LEFT CLICK MENU
# #######################
sub my_callback {
    my ($env, $port, $server);
    my %server;
    $env = shift;
    $server = ADN::CONF::Read->new();
    %server = $server->server();
    $port = $server{port};
    if (( $env & SysTray::MB_LEFT_CLICK ) || ( $env & SysTray::MB_DOUBLE_CLICK )) {
	   if ( $^O eq 'MSWin32' ) {
	    system 'explorer.exe http://127.0.0.1:' . $port . '/main';
	   }
    }
    undef $server;
    if ( $env & SysTray::MSG_SHUTDOWN ) {
	   exit 0;
    }
}
__END__
